﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QA_System
{
    class TrieNode
    {
        public int Id;
        public string Name;
        public bool IsKeyWord;
        public string EAT;
        public List<TrieNode> Children;        

        public TrieNode()
        {
            Id = -1;
            Name = "";
            IsKeyWord = false;
            EAT = "";
            Children = new List<TrieNode>();            
        }

        public TrieNode( int id, string name, bool isKeyWord, string eat)
        {
            Id = id;
            Name = name;
            IsKeyWord = isKeyWord;
            EAT = eat;
            Children = new List<TrieNode>();            
        }

        public void AddChild(TrieNode child)
        {
            this.Children.Add(child);            
        }

        public TrieNode GetChildByName(string childName)
        {
            TrieNode child = new TrieNode();
            foreach (var _child in Children)

                if (_child.Name.Contains(childName))
                {
                    child = _child;
                    break;
                }
            
            return child;
        }

        public TrieNode GetChildById(int childId)
        {
            TrieNode child = new TrieNode();
            foreach (var _child in Children)
                if (_child.Id == childId)
                {
                    child = _child;
                    break;
                }
            
            return child;
        }
        public List<TrieNode> GetAllChildren(TrieNode node)
        {
            return node.Children;
        }
        public bool HasChild()
        {
            if (Children.Count > 0) return true;
            else return false;
        }        
    }
}
